package co.edu.uniandes.moviles.rollerjudge;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Events;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import co.edu.uniandes.moviles.rollerjudge.logica.Equipo;
import co.edu.uniandes.moviles.rollerjudge.logica.RollerJudge;
import co.edu.uniandes.moviles.rollerjudge.logica.Torneo;

public class CrearPruebaActivity extends Activity{

	protected static final int DATE_DIALOG_ID = 999;
	private String torneo;
	private String genero;
	private String modalidad;
	private int max;
	private int min;
	private int distancia;

	private Spinner spinner1, spinnerTorneo, spinnerDis, spinnerMod;



	@Override
	protected void onCreate(Bundle savedInstanceState) {
		RollerJudge roller = RollerJudge.darInstancia();
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_crear_prueba);

		//spinner genero 
		spinner1 = (Spinner) findViewById(R.id.spinnerGenero);
		List<String> list2 = new ArrayList<String>();
		list2.add("Hombre");
		list2.add("Mujer");
		ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this,
			android.R.layout.simple_spinner_item, list2);
		dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner1.setAdapter(dataAdapter2);

		

		//spinner torneo
		spinnerTorneo = (Spinner) findViewById(R.id.spinner1);
		List<String> list = new ArrayList<String>();
		for(int i=0;i<roller.darTorneos().size();i++)
		{
			Torneo tor= roller.darTorneos().get(i);
			list.add(tor.getNombre());

		}

		ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, list);
		dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerTorneo.setAdapter(dataAdapter);

		//spinner  distancia
		spinnerDis = (Spinner) findViewById(R.id.spinner2);
		List<String> list3 = new ArrayList<String>();
		list3.add("1000");
		list3.add("500");
		list3.add("300");
		list3.add("200");
		ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, list3);
		dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerDis.setAdapter(dataAdapter3);

		//spinner  modalidad
		spinnerMod = (Spinner) findViewById(R.id.spinner3);
		List<String> list4 = new ArrayList<String>();
		list4.add("Grupo");
		list4.add("Individual");

		ArrayAdapter<String> dataAdapter4 = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, list4);
		dataAdapter4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerMod.setAdapter(dataAdapter4);


	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}



	@SuppressWarnings("deprecation")
	public void showDialog(String title, String message, final boolean finishAfterClose) {
		AlertDialog alertDialog = new AlertDialog.Builder(this).create();
		alertDialog.setTitle(title);
		alertDialog.setMessage(message);
		alertDialog.setButton("Aceptar", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(final DialogInterface dialog, final int which) {				
				if(finishAfterClose){
					finish();
				}
			}
		});
		alertDialog.show();
	}

	public void crearPatinador(View view){




		EditText txtMax = (EditText)findViewById(R.id.txtMax);
		max = Integer.parseInt(txtMax.getText().toString());

		EditText txtMin = (EditText)findViewById(R.id.txtMin);
		min = Integer.parseInt(txtMin.getText().toString());

		spinner1 = (Spinner) findViewById(R.id.spinnerGenero);
		spinnerTorneo = (Spinner) findViewById(R.id.spinner1);
		spinnerMod =  (Spinner) findViewById(R.id.spinner3);
		spinnerDis = (Spinner)findViewById(R.id.spinner2);

		genero = String.valueOf(spinner1.getSelectedItem());
		torneo = String.valueOf(spinnerTorneo.getSelectedItem());
		modalidad = String.valueOf(spinnerMod.getSelectedItem());
		distancia = Integer.parseInt(String.valueOf(spinnerDis.getSelectedItem()));

		//try {

			System.out.println("torneo" + torneo +" genero:" + genero +" modalidad:" + modalidad+ " distancia: "+distancia+"min: "+min + "max: "+max);
			Intent intent = new Intent(this, SeleccionarParticipantesActivity.class);
			intent.putExtra("torneo", torneo);
			intent.putExtra("genero", genero);
			intent.putExtra("modalidad", modalidad);
			intent.putExtra("distancia", distancia);
			intent.putExtra("min", min);
			intent.putExtra("max", max);
			startActivity(intent);
			//RollerJudge.darInstancia().registrarPatinador(nombre, docIdentidad, numero, email, edad, genero, grupo);
			//finish();

//		} catch(Exception e) {
//			if(e.getMessage().equals("Ya existe un patinador con ese documento."))
//				showDialog("Patinador Duplicado", e.getMessage(), false);
//		}	

	}

}


